/*
 * @Author: Qimu
 * @Date: 2020-04-14 01:10:44
 * @LastEditors: Qimu
 * @LastEditTime: 2020-07-07 22:29:32
 * @Description: file content
 * @FilePath: \vue-admin-koa2\koa2_api\app.js
 */
const Koa = require('koa');//引入Koa
const bodyParser = require('koa-bodyparser');//引入请求解析
const cors = require('koa2-cors');//引入跨域
const nodeMailer = require('nodemailer');//引入邮箱模块
const static = require('koa-static');//引入静态资源模块

//配置文件
const config = require('./module/config/config');
//引入路由
const router = require('./routes/api/admin');
//实例化模块
const app = new Koa();
app.use(cors())//跨域配置
  .use(static(`${__dirname}${config.staticPath}`))//静态资源配置
  .use(bodyParser({ strict: false }))//配置POST请求
  .use(router.routes())//使用路由
  .use(router.allowedMethods())//路由找不到时系统提示系统方法
  .listen(config.app.port, () => { console.log(`starting at port ${config.app.port}`) });
// const path = require('path');
// const session = require('koa-session');
//session配置
// app.keys = ['some secret hurr'];
// const CONFIG = {
//   key: 'koa:sess',
//   maxAge: 86400,
//   // autoCommit: true,
//   overwrite: true,
//   httpOnly: true,
//   signed: true,
//   rolling: true,
//   renew: false,
//   // sameSite: null,
// };
// app.use(session(CONFIG, app));

//中间件 公共信息
// app.use(async (ctx, next) => {
//   ctx.state.__HOST__ = `http://${ctx.request.header.host}`;
//   // console.log(ctx.state.__HOST__);
//   await next();
// });'/api/users'